package com.workcell.workdata.xthings.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.workcell.workdata.xthings.dto.DeviceServiceCallLogVo;
import com.workcell.workdata.xthings.entity.DeviceServiceCallLog;
import com.workcell.workdata.xthings.mapper.DeviceServiceCallLogMapper;
import com.workcell.workdata.xthings.service.DeviceServiceCallLogService;
import org.springframework.stereotype.Service;

/**
* @author Admin
* @description 针对表【t_device_service_call_log(服务调用表)】的数据库操作Service实现
* @createDate 2023-05-08 16:41:16
*/
@Service
public class DeviceServiceCallLogServiceImpl extends ServiceImpl<DeviceServiceCallLogMapper, DeviceServiceCallLog>
    implements DeviceServiceCallLogService{

    @Override
    public Page<DeviceServiceCallLog> vaguePage(DeviceServiceCallLogVo.SelectDataVo selectDataVo) {
		//串口设备将厂商编码置为空
		if ("0004".equals(selectDataVo.getHardwareType())){
			selectDataVo.setManufacturerCode(null);
		}
		LambdaQueryWrapper<DeviceServiceCallLog> deviceServiceCallLogCondition = new QueryWrapper<DeviceServiceCallLog>().lambda()
				.eq(ObjectUtil.isNotEmpty(selectDataVo.getHardwareType()), DeviceServiceCallLog::getHardwareType, selectDataVo.getHardwareType())
				.eq(ObjectUtil.isNotEmpty(selectDataVo.getDeviceNo()), DeviceServiceCallLog::getDeviceNo, selectDataVo.getDeviceNo())
				.eq(ObjectUtil.isNotEmpty(selectDataVo.getManufacturerCode()), DeviceServiceCallLog::getManufacturerCode, selectDataVo.getManufacturerCode())
				.eq(ObjectUtil.isNotEmpty(selectDataVo.getCallResult()), DeviceServiceCallLog::getCallResult, selectDataVo.getCallResult())
				.and(ObjectUtil.isNotEmpty(selectDataVo.getStartTime()) || ObjectUtil.isNotEmpty(selectDataVo.getEndTime())
						, i -> i.between(DeviceServiceCallLog::getCreateTime, selectDataVo.getStartTime(), selectDataVo.getEndTime()))
				.eq(ObjectUtil.isNotEmpty(selectDataVo.getEventType()), DeviceServiceCallLog::getEventType, selectDataVo.getEventType());
		Page<DeviceServiceCallLog> page = new Page<>(selectDataVo.getPageNum(), selectDataVo.getPageSize());
		page.addOrder(OrderItem.desc("create_time"));
		return this.page(page, deviceServiceCallLogCondition);
    }
}




